//
//  NKParentController.m
//  NiKi
//
//  Created by qiang chen on 16/6/23.
//  Copyright © 2016年 qiang chen. All rights reserved.
//

#import "NKParentController.h"
#import "UIButton+OxTitleAndImageType.h"
#import "NKNewsModel.h"
#import "NKParentCell.h"
#import "NKSettingController.h"
#import "NKMyCollectionController.h"

@interface NKParentController ()<UITableViewDelegate,UITableViewDataSource>{
    
    __weak IBOutlet UITableView *_tableV;
    __weak IBOutlet UIButton *_settingBtn;
    __weak IBOutlet UIButton *_downloadBtn;
    __weak IBOutlet UIButton *_collectionBtn;
    IBOutlet UIView *_tableHeadV;
    NSArray *_datas;
}

@end

@implementation NKParentController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    
    NKNewsModel *model1 = [NKNewsModel new];
    model1.title = @"每天早起空腹喝一杯温水";
    model1.content = @"一日之计在于晨，是我们再熟悉不过的俚语。人体每一要喝8杯开水，而每天早起第一杯温开水最为重要。";
    model1.imageUrl = @"http://upload-images.jianshu.io/upload_images/227071-05a3cfac70bbd00c.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
    NKNewsModel *model2 = [NKNewsModel new];
    model2.title = @"每天看书一小时";
    model2.content = @"阅读的方式除了纸质阅读，建议可以使用手机上的一些阅读APP比如“微信阅读”或购买kindle上阅读，更便宜实惠、方便携带，也能更好的利用上下班、等待排队等琐碎时间。";
    model2.imageUrl = @"http://upload-images.jianshu.io/upload_images/227071-fa7ed8ef255a33d9.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
    NKNewsModel *model3 = [NKNewsModel new];
    model3.title = @"每天刷一回知乎﻿动态";
    model3.content = @"当然现在的“简书”也是一个很好的学习交流平台.";
    model3.imageUrl = @"http://upload-images.jianshu.io/upload_images/227071-a4a8f94c57cd66ee.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
    NKNewsModel *model4 = [NKNewsModel new];
    model4.title = @"每天看一个TED视频";
    model4.content = @"TED的演讲时长一般不超过18分钟，汇聚了各行各业的牛人，观点响亮，看法新颖。如Google的创始人，Uber的创始人都在上面发表过演讲。观看TED的演讲能让走出我们固有的知识领域，从不同角度看世界。了解最新的科技发展。认识不同的人生观点，对于增长人生的阅历非常有帮助.";
    model4.imageUrl = @"http://upload-images.jianshu.io/upload_images/227071-248fe708dcd913b4.JPG?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
    
    _datas = @[model2,model3,model4,model1];
}

#pragma mark - 设置UI
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)setupUI {
     [_settingBtn layoutButtonWithEdgeInsetsStyle:OxButtonEdgeInsetsTop space:8];
     [_downloadBtn layoutButtonWithEdgeInsetsStyle:OxButtonEdgeInsetsTop space:8];
     [_collectionBtn layoutButtonWithEdgeInsetsStyle:OxButtonEdgeInsetsTop space:8];
    
    _tableV.tableHeaderView = _tableHeadV;
    [_tableV registerNib:[UINib nibWithNibName:NSStringFromClass([NKParentCell class]) bundle:nil] forCellReuseIdentifier:parentCell];
    _tableV.contentInset = UIEdgeInsetsMake(0, 0,kTabBarH - 49, 0);
    
    self.view.layer.contents = (id)[UIImage imageNamed:@"背景底图"].CGImage;
}

#pragma mark - headV事件
- (IBAction)settingBtnClick:(UIButton *)sender {
    [self.navigationController pushViewController:[NKSettingController new] animated:YES];
}

- (IBAction)myCollectionBtnClick:(UIButton *)sender {
    [self.navigationController pushViewController:[NKMyCollectionController new] animated:YES];
}

#pragma mark - tableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NKParentCell *cell = [tableView dequeueReusableCellWithIdentifier:parentCell];
    cell.model = _datas[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NKNewsModel *model = _datas[indexPath.row];
    return model.cellH;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
